from utils import ListNode, print_list


def remove_dup(mylist):
    ptr = ListNode(0)
    ptr.next = mylist
    myset = set()
    while ptr.next:
        while ptr.next.val in myset:
            # 删除节点
            ptr.next = ptr.next.next
        myset.add(ptr.next.val)
        ptr = ptr.next


list1 = ListNode(1)

list2 = ListNode(1)
node2 = ListNode(2)
node3 = ListNode(3)
node4 = ListNode(2)
node5 = ListNode(4)
list2.next = node2
node2.next = node3
node3.next = node4
node4.next = node5

print_list(list1)
remove_dup(list1)
print_list(list1)

print_list(list2)
remove_dup(list2)
print_list(list2)
